﻿
function ShowDate(cTglAsli) 
{
	//var cTgl;
    cTgl = cTglAsli 
		 if (cTgl.length !== 8) 
			{
				if (cTgl === "") 
				{
					cTgl = new Date()
				};
			   var dsl = new Date(cTgl);
				cTgl = dsl.format('Ymd')
		   };
    var cHari = cTgl.substr(6, 2);
    var cBulan = cTgl.substr(4, 2);
    var cThn = cTgl.substr(0, 4);
    var cBln = '';
    switch (cBulan) {
        case '01': cBln = 'Jan'
            break
        case '02': cBln = 'Feb'
            break
        case '03': cBln = 'Mar'
            break
        case '04': cBln = 'Apr'
            break
        case '05': cBln = 'May'
            break
        case '06': cBln = 'Jun'
            break
        case '07': cBln = 'Jul'
            break
        case '08': cBln = 'Aug'
            break
        case '09': cBln = 'Sep'
            break
        case '10': cBln = 'Oct'
            break
        case '11': cBln = 'Nov'
            break
        case '12': cBln = 'Dec'
    }
    return cHari + '/' + cBln + '/' + cThn
}

function getTanggal(cTglAsli, btmp) 
{
    if (cTglAsli === undefined) 
	{
        cTgl = new Date()
    }
	if (cTglAsli.length !== 11) 
	{
		cTgl = ShowDate(cTglAsli);
	}
	else
	{
		cTgl = cTglAsli;
	}
     
	if (cTgl.length !== 8) 
	{
		var cHari = cTgl.substr(0, 2);
		var cBulan = cTgl.substr(3, 3);
		var cThn = cTgl.substr(7, 4);
		var cBln;
		
		switch (cBulan) 
		{
			case 'Jan': cBln = '01'
				break
			case 'Feb': cBln = '02'
				break
			case 'Mar': cBln = '03'
				break
			case 'Apr': cBln = '04'
				break
			case 'May': cBln = '05'
				break
			case 'Jun': cBln = '06'
				break
			case 'Jul': cBln = '07'
				break
			case 'Aug': cBln = '08'
				break
			case 'Sep': cBln = '09'
				break
			case 'Oct': cBln = '10'
				break
			case 'Nov': cBln = '11'
				break
			case 'Dec': cBln = '12'
		}
		return cThn+cBln+cHari;
	}
	else
	{
		return cTgl;
	}
    
};

function FormatDateReport(cTglAsli) 
{
	//var cTgl;
    cTgl = cTglAsli 
		 if (cTgl.length !== 8) 
			{
				if (cTgl === "") 
				{
					cTgl = new Date()
				};
			   var dsl = new Date(cTgl);
				cTgl = dsl.format('Ymd')
		   };
    var cHari = cTgl.substr(6, 2);
    var cBulan = cTgl.substr(4, 2);
    var cThn = cTgl.substr(0, 4);
    
    return cThn + '-' + cBulan + '-' + cHari
}

function ShowYear(cTglAsli) 
{
	
	if (cTglAsli!='')
	{
		cTgl = cTglAsli 
		 if (cTgl.length !== 8) 
			{
				if (cTgl === "") 
				{
					cTgl = new Date()
				};
			   var dsl = new Date(cTgl);
				cTgl = dsl.format('Ymd')
		   };
		var cHari = cTgl.substr(6, 2);
		var cBulan = cTgl.substr(4, 2);
		var cThn = cTgl.substr(0, 4);
		var cBln = '';
		return cThn
	}
	else
	{
		return '';
	}
}

Ext.apply(Ext.form.VTypes, 
{
    daterange : function(val, field) 
	{
        var date = field.parseDate(val);

        if(!date)
		{
            return;
        }
        if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime())))
		{
            var start = Ext.getCmp(field.startDateField);
            start.setMaxValue(date);
            start.validate();
            this.dateRangeMax = date;
        } 
        else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) 
		{
            var end = Ext.getCmp(field.endDateField);
            end.setMinValue(date);
            end.validate();
            this.dateRangeMin = date;
        }
  
        return true;
    },

	MAKSTEKS : function(val, field) 
	{
        if (field.initialPassField) 
		{
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
        }
        return true;
    },
	
    password : function(val, field) 
	{
        if (field.initialPassField) 
		{
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
        }
        return true;
    },	
    passwordText : 'Passwords do not match'
});

function GetNBulan(cTglAsli) 
{
	
	if (cTglAsli!='')
	{
		cTgl = cTglAsli 
		 if (cTgl.length !== 8) 
			{
				if (cTgl === "") 
				{
					cTgl = new Date()
				};
			   var dsl = new Date(cTgl);
				cTgl = dsl.format('Ymd')
		   };
		var cHari = cTgl.substr(6, 2);
		var cBulan = cTgl.substr(4, 2);
		var cThn = cTgl.substr(0, 4);
		var cBln = '';
		return cBulan
	}
	else
	{
		return '';
	}
}

function FormatDate(cTglAsli) 
{	
    cTgl = cTglAsli 
	var cHari = cTgl.substr(6, 2);
    var cBulan = cTgl.substr(4, 2);
    var cThn = cTgl.substr(0, 4);
	return cThn + '/' + cBulan + '/' + 	 cHari
}

function ByteToBulan(nbulan) 
{	
	
    switch (nbulan) 
	{
        case '01': cBln = 'Januari'
            break
        case '02': cBln = 'Februari'
            break
        case '03': cBln = 'Maret'
            break
        case '04': cBln = 'April'
            break
        case '05': cBln = 'Mei'
            break
        case '06': cBln = 'Juni'
            break
        case '07': cBln = 'Juli'
            break
        case '08': cBln = 'Agustus'
            break
        case '09': cBln = 'September'
            break
        case '10': cBln = 'Oktober'
            break
        case '11': cBln = 'November'
            break
        case '12': cBln = 'Desember'
		
		case '1': cBln = 'Januari'
            break
        case '2': cBln = 'Februari'
            break
        case '3': cBln = 'Maret'
            break
        case '4': cBln = 'April'
            break
        case '5': cBln = 'Mei'
            break
        case '6': cBln = 'Juni'
            break
        case '7': cBln = 'Juli'
            break
        case '8': cBln = 'Agustus'
            break
        case '9': cBln = 'September'
    }
	return cBln 
}

function formatCurrency(num) 
{
    if (num != undefined) 
	{
        num = num.toString().replace(/\$|\,/g, '');
        if (isNaN(num))
            num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num * 100 + 0.50000000001);
        cents = num % 100;
        num = Math.floor(num / 100).toString();
        if (cents < 10)
            cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + '.' +
			num.substring(num.length - (4 * i + 3));
       
        return (((sign) ? '' : '-') + num);
    }
};